(function($){
    var Audit ={
        init:function(){
            this.viewBigger();
            this.pass();
            this.refuse();
            this.changeVoteBase();
            this.search();
        },
        viewBigger:function(){
            $('.viewBigger').click(function(){
                var imageUrl = $(this).attr('src');
                layer.open({
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    //area: ['600px', '600px'], //宽高
                    content: '<img src="'+imageUrl+'"/>'
                });
            });
        },
        pass:function(){
            $('.pass').click(function(){
                var userId = $(this).attr('data');
                layer.confirm('确认通过？',{
                    btn:['通过','取消']
                },function(){
                    $.ajax({
                        url:'http://wams.veryeast.cn/activity/meadin_activity/admin/index.php?a=auditHandle',
                        type:'post',
                        data:{userId:userId,type:1},
                        dataType:'json',
                        success:function(data){
                            if(data.status==1){
                                layer.msg("操作成功！",function(){
                                    window.location.reload();
                                });
                            }else{
                                layer.msg(data.message);
                            }
                        }
                    });
                });
            });
        },
        refuse:function(){
            $('.refuse').click(function(){
                var userId = $(this).attr('data');
                layer.config({
                    extend: 'extend/layer.ext.js'
                });
                layer.prompt({
                    title:'请输入审核失败理由！',
                    formType:2,
                    maxlength:100
                },function(reason){
                    $.ajax({
                        url:'http://wams.veryeast.cn/activity/meadin_activity/admin/index.php?a=auditHandle',
                        type:'post',
                        data:{userId:userId,type:2,reason:reason},
                        dataType:'json',
                        success:function(data){
                            if(data.status==1){
                                layer.msg("操作成功！",function(){
                                    window.location.reload();
                                });
                            }else{
                                layer.msg(data.message);
                            }
                        }
                    });
                });
            });
        },
        changeVoteBase:function(){
            $('.changeVoteBase').click(function(){
                var userId = $(this).attr('data');
                layer.config({
                    extend: 'extend/layer.ext.js'
                });
                layer.prompt({
                    titlt:'请输入投票基数！',
                    formType:0,
                    maxlength:100
                },function(base){
                    base = parseInt(base);
                    if( isNaN(base) || base<0){
                        layer.msg("请输入正整数！");
                        return false;
                    }
                    $.ajax({
                        url:'http://wams.veryeast.cn/activity/meadin_activity/admin/index.php?a=auditHandle',
                        type:'post',
                        data:{userId:userId,type:3,base:base},
                        dataType:'json',
                        success:function(data){
                            if(data.status==1){
                                layer.msg("操作成功！",function(){
                                    window.location.reload();
                                });
                            }else{
                                layer.msg(data.message);
                            }
                        }
                    });
                });
            });
        },
        search:function(){
            $('#submit').click(function(){
                var search = $('#search').val();
                var url = $(this).attr('url');
                if(search){
                    window.location.href = url+'search='+search;
                }else{
                    window.location.href = url;
                }

            });
        }

    };
    Audit.init();
})(jQuery);